﻿Imports System.Data.SqlClient

Public Class adm_cn_productsubmitpic
    Inherits System.Web.UI.Page
    Private sSQL As String
    Private objrd As SqlDataReader = Nothing
    Private objfind As New GetData
    Private ps As New PreparedStatement(sSQL)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim productId, strErr, id, path, photoType As String
        strErr = ""
        If (Session("admin_ID") <> Nothing And Session("admin_ID") <> "") Then
            If (Request("uid") <> Nothing And Request("uid") <> "") Then
                If (Request("productId") <> Nothing And Request("productId") <> "") Then
                    If (Request("submitproductimage") <> Nothing And Request("submitproductimage") <> "") Then
                        productId = Request("productId")
                        Dim i As Integer
                        For i = 0 To Request.Files.Count - 1
                            Dim myFile As HttpPostedFile = Request.Files(i)
                            If (myFile.ContentLength <> 0) Then
                                System.IO.Directory.CreateDirectory(Server.MapPath("../../") & "pic/product/" & productId)
                                myFile.SaveAs(Server.MapPath("../../") & "pic/product/" & productId & "/" & myFile.FileName.ToString)
                                path = "/pic/product/" & productId & "/" & myFile.FileName.ToString
                                id = System.Guid.NewGuid().ToString()
                                photoType = myFile.FileName.Substring(myFile.FileName.LastIndexOf(".") + 1)
                                ps.strSql = "insert into product_photo(path,product_id,photo_type) values(@path,@productId,@photoType)"
                                ps.parameters.Clear()
                                ps.addParameter("path", path)
                                ps.addParameter("productId", productId)
                                ps.addParameter("photoType", True)
                                objfind.es(ps, strErr)
                            End If
                        Next
                        Response.Redirect("adm_cn_supplyManagement.aspx?uid=" & Request("uid"))
                    End If
                End If

            Else
                Response.Redirect("../memberMngt_default.aspx")
            End If
        Else
            Response.Redirect("../adm_login.aspx")
        End If

    End Sub
End Class